package org.chandler.ccgp.parser;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

public class PageParser {
	/**
	 * 通过url解析单页详细招标信息
	 * @param url
	 * @return
	 * @throws IOException 
	 * @throws MalformedURLException 
	 */
	public static String getDivDetailContent(String url) throws MalformedURLException, IOException{
		Document doc = Jsoup.parse(new URL(url).openStream(), "UTF-8", url);
		Elements es = doc.select("[class=\"vT_detail_content w760c\"]");
		if(es.size() > 0){
			return es.get(0).toString();
		}
		return null;
	}
	/**
	 * 通过url解析单页纯文本
	 * @param url
	 * @return
	 * @throws IOException 
	 * @throws MalformedURLException 
	 */
	public static String getDivText(String url) throws MalformedURLException, IOException{
		Document doc = Jsoup.parse(new URL(url).openStream(), "UTF-8", url);
		Elements es = doc.select("[class=\"vT_detail_content w760c\"]");
		if(es.size() > 0){
			return es.get(0).text();
		}
		return null;
	}
	public static void main(String[] args) throws Exception {
		//String t = getDivDetailContent("http://www.ccgp.gov.cn/cggg/dfgg/gkzb/201507/t20150722_5599915.htm");
		String t = getDivText("http://www.ccgp.gov.cn/cggg/dfgg/gkzb/201507/t20150722_5599540.htm");
		System.out.println(t);
	}
}
